package frontend.pages.admin.activity;

import backend.model.admin.Activity;
import backend.service.admin.ActivityService;
import frontend.core.TimeTrackingWebApplication;
import frontend.model.admin.ActivityUIModel;
import frontend.pages.admin.base.AbstractManagingPage;
import org.apache.wicket.markup.html.panel.Panel;
import org.wicketstuff.annotation.mount.MountPath;

import java.util.List;

@MountPath("activity")
public class ActivityManagingPage extends AbstractManagingPage<Activity> {

    public ActivityManagingPage() {
        super("pages.admin.activity.title", "contextualHelp.admin.activity.text");
    }

    @Override
    protected String getAddPanelTitleKey() {
        return "pages.admin.activity.add.title";
    }

    @Override
    protected String getEditPanelTitleKey() {
        return "pages.admin.activity.edit.title";
    }

    @Override
    protected String getNoSelectionMessageKey() {
        return "pages.admin.activity.edit.noSelection";
    }

    @Override
    protected Panel getAddPanel(String panelId) {
        return new ActivityPanel(panelId, getPageParameters(), new ActivityUIModel());
    }

    @Override
    protected Panel getEditPanel(String panelId, Activity activity) {
        getPageParameters().clearNamed();
        return new ActivityPanel(panelId, null, new ActivityUIModel(activity));
    }

    @Override
    public List<Activity> loadAvailableEntities() {
        ActivityService activityService = TimeTrackingWebApplication.getService(ActivityService.class);
        return activityService.findAllActivities();
    }
}
